package com.msb.mall.ware.controller;

import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;
import com.msb.mall.ware.entity.PurchaseEntity;
import com.msb.mall.ware.service.PurchaseService;
import com.msb.mall.ware.vo.PurchaseFinishVo;
import com.msb.mall.ware.vo.PurchaseMergeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 采购信息
 *
 * @author lwq
 * @email 1907326957@qq.com
 * @date 2024-06-12 22:26:37
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;


    /**
     * 采购完成
     */
    @PostMapping("/finish")
    public R finish(@RequestBody PurchaseFinishVo finishVo){
        purchaseService.finish(finishVo);
        return R.ok();
    }
    /**
     * 领取采购单
     */
    @PostMapping("/receive")
    public R receive(@RequestBody List<Long> ids){
        purchaseService.receive(ids);
        return R.ok();
    }
    /**
     * 采购单合并
     */
    @PostMapping("/merge")
    public R merge(@RequestBody PurchaseMergeVo purchaseMergeVo){
        Integer flag =purchaseService.merge(purchaseMergeVo);
        if (flag == -1){
            return R.error("合并失败。。。该采购单不能被合并！");
        }
        return R.ok();
    }
    /**
     * 列表
     */
    @GetMapping("/unreceive/list")
    public R unReceiveList(@RequestParam Map<String, Object> params){
        List<PurchaseEntity> purchaseEntities = purchaseService.unReceiveList(params);
        return R.ok().put("data", purchaseEntities);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
